package com.woniuxy.huayoung.service.impl;

import com.woniuxy.huayoung.entity.HotelReview;
import com.woniuxy.huayoung.entity.TravelReview;
import com.woniuxy.huayoung.entity.Verify;
import com.woniuxy.huayoung.mapper.HotelReviewMapper;
import com.woniuxy.huayoung.mapper.TravelReviewMapper;
import com.woniuxy.huayoung.mapper.VerifyMapper;
import com.woniuxy.huayoung.service.HotelReviewService;
import com.woniuxy.huayoung.service.TravelReviewService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class HotelReviewServiceImpl implements HotelReviewService {
    @Resource
    private VerifyMapper verifyMapper;
    @Resource
    private HotelReviewMapper hotelReviewMapper;


    @Override
    public List<HotelReview> findByUid(int uid) {

        return hotelReviewMapper.findByUid(uid);
    }

    @Override
    public List<HotelReview> findAll() {
        return hotelReviewMapper.findAll();
    }

    @Override
    public List<HotelReview> verify() {
        return hotelReviewMapper.verify();
    }

    @Override
    public List<HotelReview> verifypass(int id) {
        hotelReviewMapper.verifypass(id);
        List<HotelReview> verify = hotelReviewMapper.verify();
        return verify;
    }

    //审核不通过，修改状态，将信息记录到verify表中
    @Transactional
    @Override
    public List<HotelReview> verifynotpass(Map<String,Object> map) {
        Integer type =(Integer) map.get("type");
        Integer contextId =(Integer) map.get("id");
        Integer uid = (Integer)map.get("uid");
        String message = (String)map.get("message");
        //不通过修改status
        hotelReviewMapper.verifynotpass(contextId);
        //
        //创建verify对象存进数据库
        Verify verify = new Verify(type, contextId, message, uid);
        verifyMapper.add(verify);

        //重新查询审核中的数据
        List<HotelReview> reviews = hotelReviewMapper.verify();
        return reviews;
    }
}



